Accessing Null Reference (ANR)

Description:

ANR detects cases where evaluation of a field reference expression will result in a System.NullReferenceException being thrown. ANR is reported whenever a non-static field of an object or array is accessed and the left operand of the . (field access) operator has the nil value.

Incorrect:

procedure PrintMessage(msg:MyMessage);
begin
    if msg <> nil then
        msg.Print()
    else
        Console.WriteLine(msg.ToString() + ' is null');
end;

Correct:

procedure PrintMessage(msg:MyMessage);
begin
    if msg <> nil then
        msg.Print()
    else
        Console.WriteLine('msg is null');
end;